﻿@page "/SysConfig/Details/{id}"
@using SelfService.ViewModel.SysConfigVMs;
@using SelfService.Model
@inherits BasePage

<ValidateForm @ref="VForm" Model="@_model" >
    <Row ItemsPerRow="ItemsPerRow.One" RowType="RowType.Normal">
        <Display @bind-Value="@_model.Entity.Key" ShowLabel="true"/>
        <Display @bind-Value="@_model.Entity.ValueType" ShowLabel="true"/>
        @if (_model.Entity.ValueType == SysConfigValueTypeEnum.文件)
        {
            <img src="@Src" width="150" height="150" alt=""/>
        }
        else
        {
            <Display @bind-Value="@_model.Entity.Value" ShowLabel="true"/>
        }
        <Display @bind-Value="@_model.Entity.Description" ShowLabel="true"/>
        <Display @bind-Value="@_model.Entity.GroupId" Lookup="@_allSysConfigGroups"  ShowLabel="true"/>
    </Row>
    <div class="modal-footer table-modal-footer">
        <Button Color="Color.Primary" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Close"]" OnClick="OnClose"></Button>
    </div>
</ValidateForm>

@code {
    private SysConfigVm _model = null;
    private ValidateForm VForm { get; set; }
    [Parameter]
    public string Id { get; set; }
    private string Src { get; set; }
    private List<SelectedItem> _allSysConfigGroups = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {
        _allSysConfigGroups = await WtmBlazor.Api.CallItemsApi("/api/SysConfig/GetSysConfigGroups", placeholder: WtmBlazor.Localizer["Sys.All"]);
        var rv = await WtmBlazor.Api.CallAPI<SysConfigVm>($"/api/SysConfig/{Id}");
        _model = rv.Data;
        if (_model.Entity.ValueType == SysConfigValueTypeEnum.文件)
        {
            Src = await WtmBlazor.GetBase64Image(_model.Entity.Value, 150, 150);
        }
    }

    public void OnClose()
    {
        CloseDialog();
    }

}
